Operating systems are responsible for the management and coordination of activities of a computer and the distribution of the computer's limited resources. Typically, resources are shared between many software applications running in the environment of the operating system. Often the operating system employs locking code (or simply ‘locks’) to reserve a resource for use by a particular process. The lock reserves (or locks) the resource, the lock holder uses the resource, and then the lock on the resource is released when the lock holder is finished.
Locks are often a cause of software errors that negatively affect the operation of the computer. A classical situation is that of a deadlock, where a process cannot meet a condition to move to another state, such as when a process fails to release the lock and other processes will continue to wait for the resource. In another type of deadlock, two threads are unable to proceed because each one of them is waiting for something to be done by the other. For example, the deadlock may occur when a first thread is waiting for a variable that has already been locked by a second thread, and at the same time the second thread is waiting for another variable that has already been locked by the first thread. Another type of deadlock occurs when a process has the lock, but doesn't realize it, and thus continues to wait for the lock.